import { reactive } from "vue"


// 公司基本信息
interface EBasicInfo {
  name: string;
  nature: string;
  industry: string;
  sizeMin: string;
  sizeMax: string;
  content: string;
}

export const eBasicInfo = reactive<EBasicInfo>({
  name: "",
  nature: "",
  industry: "",
  sizeMin: "",
  sizeMax: "",
  content: ""
})
interface EBasicInfoRules {
  name: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  nature: {
    required: boolean;
    message: string;
    trigger: string;
  }[];
  industry: {
    message: string;
    required: boolean;
    trigger: string;
  }[];
}

export const eBasicInfoRules = reactive<EBasicInfoRules>({
  name: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],
  nature: [
    {
      required: true,
      message: '请选择公司性质',
      trigger: 'change',
    },
  ],
  industry: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
  ],
})

// 公司优势
interface EAdvantage {
  advantage: Array<string>
}

export const eAdvantage = reactive<EAdvantage>({
  advantage: []
})

interface EAdvantageRules {
  advantage: {
    type: string;
    required: boolean;
    message: string;
    trigger: string;
  }[];
}

export const eAdvantageRules = reactive<EAdvantageRules>({
  advantage: [
    {
      type: 'array',
      required: true,
      message: '最少选择一个',
      trigger: 'change',
    },
  ],
})

// 公司联系方式和地址
interface EContact {
  contactName: string;
  contactPhone: string;
  contactEmail: string;
  contactAddress: string;
}

export const eContact = reactive<EContact>({
  contactName: "",
  contactPhone: "",
  contactEmail: "",
  contactAddress: "",
})

interface EcontactRules {
  contactName: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[]; contactPhone: ({
    required: boolean;
    message: string;
    trigger: string;
    pattern?: undefined;
  } | {
    pattern: RegExp;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  contactEmail: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
  }[];
  contactAddress: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
}

export const eContactRules = reactive<EcontactRules>({

  contactName: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],
  contactPhone: [
    { required: true, message: "请输入手机号", trigger: "blur" },
    // 这个只能验证手机号
    // { pattern:/^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/, message: "请输入合法手机号", trigger: "blur" }
    { pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: "请输入合法手机号/电话号", trigger: "blur" }
  ],

  contactEmail: [
    {
      type: "email",
      message: "请正确输入邮箱",
      required: true,
      trigger: "blur",
    },
  ],

  contactAddress: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],


})

// 公司工商信息
interface EBusinessInfo {
  businessName: string;
  businessSetTime: string;
  businessRegCapital: string;
  businessLegalRepresentative: string;
}

export const eBusinessInfo = reactive<EBusinessInfo>({
  businessName: "",
  businessSetTime: "",
  businessRegCapital: "",
  businessLegalRepresentative: "",
})


interface EBusinessInfoRules {
  businessName: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  businessSetTime: {
    type: string;
    required: boolean;
    message: string;
    trigger: string;
  }[];
  businessRegCapital: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  businessLegalRepresentative: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
}


export const eBusinessInfoRules = reactive<EBusinessInfoRules>({

  businessName: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],

  businessSetTime: [
    {
      type: 'date',
      required: true,
      message: '请选择时间',
      trigger: 'change',
    },
  ],

  businessRegCapital: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 1,
      max: 10,
      message: "长度在1到10个字符",
      trigger: "blur",
    },
  ],
  businessLegalRepresentative: [
    {
      message: "此处不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 10,
      message: "长度在2到10个字符",
      trigger: "blur",
    },
  ],



})

interface UpHRPwd {
  name: string;
  oldPwd: string;
  password_1: string;
  password_2: string;
  detail: string;
  
}

export const upHRPWd = reactive<UpHRPwd>({
  name: "",
  oldPwd: "",
  password_1: "",
  password_2: "",
  detail:"",

})

interface UpHRPwdRules {
  oldPwd: ({
    required: boolean;
    message: string;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  password_1: ({
    required: boolean;
    message: string;
    trigger: string;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
  })[];
  password_2: ({
    required: boolean;
    message: string;
    trigger: string;

  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;

  } | {
    validator: (rule: UpHRPwdRules, value: string, callback: any) => void;
    trigger: string;
  })[];
}

const validatePass_2 = (rule: UpHRPwdRules, value: string, callback: any) => {
  if (value === "") {
    callback(new Error("请再次输入密码"));
  } else if (value !== upHRPWd.password_1) {
    callback(new Error("两次输入密码不一致!"));
  } else {
    callback();
  }
};
export const upHRPWdRules = reactive<UpHRPwdRules>({
  oldPwd: [
    {
      required: true,
      message: "请输入你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 20,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
  ],
  password_1: [
    {
      required: true,
      message: "请输入你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 20,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
  ],
  password_2: [
    {
      required: true,
      message: "请确认你的密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 30,
      message: "密码长度在6到20个字符",
      trigger: "blur",
    },
    { validator: validatePass_2, trigger: "blur" },
  ],

})

interface UpHRInfo {
  hrId: string;
  hrName: string;
  hrGender: string;
  hrPhone: string;
  hrEmail: string;
  hrSignature: string;
}

export const upHRInfo = reactive<UpHRInfo>({
  hrId: "",
  hrName: "",
  hrGender: "",
  hrEmail: "",
  hrPhone: "",
  hrSignature: ""
})
interface UpHRInfoRules {
  hrName: ({
    message: string;
    required: boolean;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  hrGender: {
    message: string;
    required: boolean;
    trigger: string;
  }[];
  hrPhone: ({
    required: boolean;
    message: string;
    trigger: string;
    pattern?: undefined;
  } | {
    pattern: RegExp;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
  hrEmail: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
  }[];
}


export const upHRInfoRules = reactive<UpHRInfoRules>({
  hrName: [
    {
      message: "用户名不能为空",
      required: true,
      trigger: "blur",
    },
    {
      min: 2,
      max: 30,
      message: "长度在2到30个字符",
      trigger: "blur",
    },
  ],
  hrGender: [
    {
      message: "请选择你的性别",
      required: true,
      trigger: "change",
    },
  ],
  hrPhone: [
    { required: true, message: "请输入手机号", trigger: "blur" },
    // 这个只能验证手机号
    // { pattern:/^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/, message: "请输入合法手机号", trigger: "blur" }
    { pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: "请输入合法手机号/电话号", trigger: "blur" }
  ],

  hrEmail: [
    {
      type: "email",
      message: "请正确输入邮箱",
      required: true,
      trigger: "blur",
    },
  ],
})
